﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.AdminCP;
using VINETLIFE.BL;
using VINETLIFE.DO;

namespace VINETLIFE.AdminCP
{
    public partial class ListDoiTac : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Functions.bindToDropDown(ddlPartnerType, new cmsPartnerTypeBL().SelectAll(), cmsPartnerTypeDO.PARENTID_FIELD, cmsPartnerTypeDO.PARTNERTYPEID_FIELD, cmsPartnerTypeDO.PARTNERTYPE_FIELD);
                grvBusinessPartnerDataSource();
            }
        }

        protected void ddlPartnerType_SelectedIndexChanged(object sender, EventArgs e)
        {
            grvBusinessPartnerDataSource();
        }
        private void grvBusinessPartnerDataSource()
        {
            grvBusinessPartner.DataSource = new cmsDoiTacBL().SelectByTypeAdmin(int.Parse(ddlPartnerType.SelectedValue));
            grvBusinessPartner.DataBind();
        }

        protected void grvBusinessPartner_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvBusinessPartner.PageIndex = e.NewPageIndex;
            grvBusinessPartnerDataSource();
        }

        protected void grvBusinessPartner_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                new cmsDoiTacBL().Delete(new cmsDoiTacDO { DoiTacID = Convert.ToInt32(grvBusinessPartner.DataKeys[e.RowIndex].Value) });
                Functions.Alert("Xóa bản tin thành công!", Request.Url.ToString());
            }
            catch
            {
                Functions.Alert("Có lỗi xảy ra!", Request.Url.ToString());
            }
        }
        protected void grvBusinessPartner_SelectedIndexChanged(object sender, EventArgs e)
        {
            int DoiTacId = Convert.ToInt32(grvBusinessPartner.DataKeys[grvBusinessPartner.SelectedIndex].Value);
            Response.Redirect("DoiTac.aspx?DoiTacId=" + DoiTacId);
           
        }
        protected void grvBusinessPartner_RowCommand(object sender, GridViewCommandEventArgs e)
        {
        }
    }
}